using Circus.CodeEditor;
using Circus.Syntax;
using System;
using System.ComponentModel;
namespace Circus.CodeEditor.TextSource
{
	public class StringItem
	{
		private string str;
		private int lexState;
		private int prevLexState;
		private ItemState state;
		private StringItemInfo[] textData;
		[Description("Gets or sets string content of the \"IStringItem\".")]
		public virtual string String
		{
			get
			{
				return this.str;
			}
			set
			{
				if (this.str != value)
				{
					this.str = value;
					this.OnStringChanged();
				}
			}
		}
		[Description("Gets or sets information of the \"IStringItem\".")]
		public virtual StringItemInfo[] TextData
		{
			get
			{
				return this.textData;
			}
			set
			{
				if (this.textData != value)
				{
					this.textData = value;
					this.OnTextDataChanged();
				}
			}
		}
		[Description("Gets or sets current state of the \"IStringItem\".")]
		public virtual ItemState State
		{
			get
			{
				return this.state;
			}
			set
			{
				if (this.state != value)
				{
					this.state = value;
					this.OnStateCahnged();
				}
			}
		}
		[Description("Gets or sets index of lexical state at item end.")]
		public virtual int LexState
		{
			get
			{
				return this.lexState;
			}
			set
			{
				if (this.lexState != value)
				{
					this.lexState = value;
					this.OnLexStateChanged();
				}
			}
		}
		[Description("Gets or sets index of lexical state at item start.")]
		public virtual int PrevLexState
		{
			get
			{
				return this.prevLexState;
			}
			set
			{
				if (this.prevLexState != value)
				{
					this.prevLexState = value;
					this.OnPrevLexStateChanged();
				}
			}
		}
		protected virtual void OnStringChanged()
		{
			this.textData = new StringItemInfo[this.str.Length];
		}
		protected virtual void OnTextDataChanged()
		{
		}
		protected virtual void OnStateCahnged()
		{
		}
		protected virtual void OnLexStateChanged()
		{
		}
		protected virtual void OnPrevLexStateChanged()
		{
		}
		public static void SetTextStyle(ref StringItemInfo[] textData, int start, int len, TextStyle style)
		{
			for (int i = start; i < start + len; i++)
			{
				StringItemInfo[] expr_0E_cp_0 = textData;
				int expr_0E_cp_1 = i;
				expr_0E_cp_0[expr_0E_cp_1].TextStyle = (expr_0E_cp_0[expr_0E_cp_1].TextStyle | style);
			}
		}
		public static void ClearTextStyle(ref StringItemInfo[] textData, int start, int len, TextStyle style)
		{
			for (int i = start; i < start + len; i++)
			{
				StringItemInfo[] expr_0E_cp_0 = textData;
				int expr_0E_cp_1 = i;
				expr_0E_cp_0[expr_0E_cp_1].TextStyle = (expr_0E_cp_0[expr_0E_cp_1].TextStyle & ~style);
			}
		}
		public static string[] Split(string text)
		{
			return (text != null && text != string.Empty) ? text.Replace("\r\n", '\r'.ToString()).Split(Consts.crlfArray, int.MaxValue) : new string[0];
		}
		public StringItem(string s)
		{
			this.String = s;
		}
		public virtual void SetTextStyle(int start, int len, TextStyle style)
		{
			StringItem.SetTextStyle(ref this.textData, start, len, style);
		}
		public virtual void ClearTextStyle(int start, int len, TextStyle style)
		{
			StringItem.ClearTextStyle(ref this.textData, start, len, style);
		}
		public virtual TextStyle TextStyleAt(int pos)
		{
			return this.textData[pos].TextStyle;
		}
	}
}
